package com.lemon.message.service.impl;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.lemon.common.core.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lemon.common.security.utils.OptEntityUtils;
import com.lemon.common.security.service.BaseServiceImpl;
import com.lemon.message.mapper.BiEmailTemplateMapper;
import com.lemon.message.domain.BiEmailTemplate;
import com.lemon.message.service.IBiEmailTemplateService;

/**
 * 包名称：com.lemon.message.service.impl
 * 类名称：BiEmailTemplateServiceImpl
 * 类描述：邮件模板Service业务层处理
 * 创建人：@author lemon
 * 创建时间：2023-11-18
 */
@Service
public class BiEmailTemplateServiceImpl extends BaseServiceImpl<BiEmailTemplate> implements IBiEmailTemplateService {

    @Autowired
    private BiEmailTemplateMapper biEmailTemplateMapper;

    @Override
    public int insert(BiEmailTemplate model) {
        OptEntityUtils.preInsert(model);
        // 设置url网络附件
        if (CollUtil.isNotEmpty(model.getAttachUrlList())) {
            model.setAttachUrl(CollUtil.join(model.getAttachUrlList(), Constants.STR_SEMI));
        }
        return biEmailTemplateMapper.insertSelective(model);
    }

    @Override
    public int update(BiEmailTemplate model) {
        // 设置url网络附件
        if (CollUtil.isNotEmpty(model.getAttachUrlList())) {
            model.setAttachUrl(CollUtil.join(model.getAttachUrlList(), Constants.STR_SEMI));
        }
        OptEntityUtils.preUpdate(model);
        return biEmailTemplateMapper.updateByPrimaryKeySelective(model);
    }

    @Override
    public List<BiEmailTemplate> selectBiEmailTemplateList(BiEmailTemplate biEmailTemplate) {
        return biEmailTemplateMapper.selectBiEmailTemplateList(biEmailTemplate);
    }
}
